﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Reflection;

namespace T5task4
{
    public partial class AddGameForm : Form
    {
        public AddGameForm()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
        
            string game = this.txtName.Text;
            string cb = this.cbCategory.Text;
            
            
                //从RadioButton中获取游戏状态
                string state = "";
                if (rbStateDev.Checked)
                {
                    state = rbStateDev.Text;
                }
                else if (rbStateTest.Checked)
                {
                    state = rbStateTest.Text;
                }
                else
                {
                    state = rbStatePub.Text;
                }
                //从CheckBox中获取游戏特色
                string tags = "";
                if (cbTag1.Checked)
                    tags += cbTag1.Text + ",";
                if (cbTag2.Checked)
                    tags += cbTag2.Text + ",";
                if (cbTag3.Checked)
                    tags += cbTag3.Text + ",";
                if (cbTag4.Checked)
                    tags += cbTag4.Text + ",";
                if (cbTag5.Checked)
                    tags += cbTag5.Text + ",";

                string sql =string.Format( "insert Li(GameName,Customer,Anarchy,Style)select '{0}','{1}','{2}','{3}'",game,cb,state,tags);
                bool dr = DBHelper.GetNonQuery(sql);

            if (dr)
            {
                MessageBox.Show("添加成功", "提示");
                this.Close();
            }
            else
            {
                MessageBox.Show("添加失败", "提示");
            }
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void AddGameForm_Load(object sender, EventArgs e)
        {
            try
            {
                string sql = string.Format("select Customer from Li1");
                SqlDataReader bd = DBHelper.Select(sql);
                while (bd.Read())
                {
                    this.cbCategory.Items.AddRange(new object[] {bd["Customer"] });
                }
                //设置组合框的DisPlayMember 属性
                cbCategory.DisplayMember = "bd";
                //设置组合框的ValueMember 属性
                cbCategory.ValueMember = "bd";
                bd.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("出现错误!"+ex.Message);
            }
        }
    }
}
